Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.Environment
Imports System.Windows.Forms
Imports DevExpress.CodeRush.Core
Imports DevExpress.CodeRush.PlugInCore
Imports DevExpress.CodeRush.StructuralParser

Namespace DX_Samples
	''' <summary>
	''' Summary description for DuplicateAsComment.
	''' </summary>
  Public Class DuplicateAsComment
	 Inherits StandardPlugIn
        Friend WithEvents actDuplicateAsComment As DevExpress.CodeRush.Core.Action
#Region "Standard Plugin Goodness :)"
#Region " private fields... "
        Private components As System.ComponentModel.IContainer
#End Region

        ' constructor...
#Region " DuplicateAsComment "
        Public Sub New()
            ''' <summary>
            ''' Required for Windows.Forms Class Composition Designer support
            ''' </summary>
            InitializeComponent()
        End Sub
#End Region

        ' CodeRush-generated code
#Region " InitializePlugIn "
        Public Overrides Sub InitializePlugIn()
            MyBase.InitializePlugIn()

            '
            ' TODO: Add your initialization code here.
            '
        End Sub
#End Region
#Region " FinalizePlugIn "
        Public Overrides Sub FinalizePlugIn()
            '
            ' TODO: Add your finalization code here.
            '

            MyBase.FinalizePlugIn()
        End Sub
#End Region

#Region " Component Designer generated code "
        ''' <summary>
        ''' Required method for Designer support - do not modify
        ''' the contents of this method with the code editor.
        ''' </summary>
        Private Sub InitializeComponent()
            Me.components = New System.ComponentModel.Container
            Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(DuplicateAsComment))
            Me.actDuplicateAsComment = New DevExpress.CodeRush.Core.Action(Me.components)
            CType(Me.actDuplicateAsComment, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me, System.ComponentModel.ISupportInitialize).BeginInit()
            '
            'actDuplicateAsComment
            '
            Me.actDuplicateAsComment.ActionName = "Duplicate as Comment"
            Me.actDuplicateAsComment.ButtonText = "Duplicate as Comment"
            Me.actDuplicateAsComment.CommonMenu = DevExpress.CodeRush.Menus.VsCommonBar.None
            Me.actDuplicateAsComment.Description = "dupolicates the selected text as a Comment"
            Me.actDuplicateAsComment.Image = CType(resources.GetObject("actDuplicateAsComment.Image"), System.Drawing.Bitmap)
            Me.actDuplicateAsComment.ImageBackColor = System.Drawing.Color.FromArgb(CType(0, Byte), CType(254, Byte), CType(0, Byte))
            CType(Me.actDuplicateAsComment, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me, System.ComponentModel.ISupportInitialize).EndInit()

        End Sub
#End Region

#End Region
        Private Sub actDuplicateAsComment_Execute(ByVal ea As DevExpress.CodeRush.Core.ExecuteEventArgs) Handles actDuplicateAsComment.Execute
            Dim ActiveDoc As TextDocument = CodeRush.Documents.ActiveTextDocument
            If ActiveDoc Is Nothing Then
                Exit Sub
            End If
            Dim Selection As SelectionServices = CodeRush.Selection
            If Selection.Text = String.Empty Then
                Exit Sub
            End If
            Dim Comment As String = CodeRush.Language.GetComment(Selection.Text) & NewLine

            Dim Insertpoint As SourcePoint = Selection.Active.Range.Start.OffsetPoint(0, -(Selection.Active.Range.Start.Offset))
            ActiveDoc.InsertText(Insertpoint, Comment)
        End Sub

    End Class
End Namespace
